package com.example.dbmeta.meta.jpatable;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.time.Instant;

public interface MetaJpaRepository extends JpaRepository<TableMetaInfo, Long> {
    // 自定义查询方法
    @Modifying
    @Query("DELETE FROM TableMetaInfo e WHERE e.codecreateTime >= :start AND e.codecreateTime < :end")
    @Transactional
    void deleteByCreateTimeBetween(@Param("start") Instant start, @Param("end") Instant end);

    /**
     * 删除早于指定时间点的所有记录
     *
     * @param cutoffTime 截止时间点（早于此时间点的记录将被删除）
     */
    @Modifying
    @Query("DELETE FROM TableMetaInfo e WHERE e.codecreateTime < :cutoffTime")
    @Transactional
    int deleteByCreateTimeBefore(@Param("cutoffTime") Instant cutoffTime);
}
